﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'PRC_TB_USER_TASK_HISTORY_CHANGE_REQUEST_MOTIVATION_SE')
	BEGIN
		DROP  Procedure  dbo.PRC_TB_USER_TASK_HISTORY_CHANGE_REQUEST_MOTIVATION_SE
	END

GO

CREATE Procedure dbo.PRC_TB_USER_TASK_HISTORY_CHANGE_REQUEST_MOTIVATION_SE
	(
		@TUHM_HISTORY_ID INT,
		@TUHM_CHANGE_REQUEST_MOTIVATION_ID INT
	)
AS


select
	TCM_ID,
	TCM_DESCRIPTION
from TB_USER_TASK_HISTORY_CHANGE_REQUEST_MOTIVATION
	inner join TB_CHANGE_REQUEST_MOTIVATION
		on TUHM_CHANGE_REQUEST_MOTIVATION_ID = TCM_ID
where TUHM_HISTORY_ID = @TUHM_HISTORY_ID
and (@TUHM_CHANGE_REQUEST_MOTIVATION_ID is null or TUHM_CHANGE_REQUEST_MOTIVATION_ID = @TUHM_CHANGE_REQUEST_MOTIVATION_ID)
order by TCM_DESCRIPTION

GO

GRANT EXEC ON dbo.PRC_TB_USER_TASK_HISTORY_CHANGE_REQUEST_MOTIVATION_SE TO PUBLIC

GO

